package com.javaear.zblog4java.desktop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.javaear.generalmapper.GeneralMapper;
import com.javaear.zblog4java.system.component.AppConfig;
import com.javaear.zblog4java.system.entity.model.ArticleModel;
import com.javaear.zblog4java.system.entity.model.CategoryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexView {

    @Autowired
    private GeneralMapper generalMapper;

    @RequestMapping("index")
    public String index(ModelMap modelMap) {
        int pageNo = 1;
        modelMap.put("blog-title", AppConfig.settingMap.get("App-blogTitle"));
        modelMap.put("blog-sub-title", AppConfig.settingMap.get("App-blogSubTitle"));
        modelMap.put("categorys", generalMapper.selectList(new EntityWrapper<>(new CategoryModel())));
        Page<ArticleModel> page = new Page<>(pageNo, (int) AppConfig.settingMap.get("App-deskPageSize"));
        modelMap.put("articles", generalMapper.selectPage(page, new EntityWrapper<>(new ArticleModel())));
        return "desktop/default/index";
    }
}
